package com.sfac.modules.account.service.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sfac.modules.account.domain.Resources;
import com.sfac.modules.account.domain.Role;
import com.sfac.modules.account.domain.RoleResource;
import com.sfac.modules.account.mapper.ResourceMapper;
import com.sfac.modules.account.mapper.RoleResourceMapper;
import com.sfac.modules.account.service.ResourceService;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author:唐琳的爹
 * @BelongsProject:hqyj_springboot
 * @BelongsPackage:com.sfac.modules.account.service.serviceimpl
 * @CreateTime:2022/8/28 19:58:28
 */
@Service
public class ResourceServiceImpl implements ResourceService {

    @Autowired
    private RoleResourceMapper roleResourceMapper;
    @Autowired
    private ResourceMapper resourceMapper;


    /**
     * 根据角色id查询所有权限
     * @param id
     * @return
     */
    @Override
    public List<Resources> getResourcesByRoleId(String id) {
        LambdaQueryWrapper<RoleResource> lqw = new LambdaQueryWrapper<>();
        lqw.eq(RoleResource::getRoleId,id);
        List<RoleResource> rr = roleResourceMapper.selectList(lqw);
        ArrayList<Resources> list = new ArrayList<>();
        rr.stream().forEach(r ->{
            list.add(resourceMapper.selectById(r.getResourceId()));
        });
        return list;
    }
}
